package com.usian.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.auth.mapper.AuthMapper;
import com.usian.auth.service.AuthService;
import com.usian.user.model.common.dtos.PageResponseResult;
import com.usian.user.model.common.dtos.ResponseResult;
import com.usian.user.model.common.enums.AppHttpCodeEnum;
import com.usian.user.model.user.dtos.AuthDto;
import com.usian.user.model.user.pojos.ApUserRealname;
import org.springframework.stereotype.Service;

@Service
public class AuthServiceImpl extends ServiceImpl<AuthMapper, ApUserRealname>implements AuthService {
    @Override
    public ResponseResult loadListByStatus(AuthDto dto) {
      //1.检查参数
        if (dto==null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        //2.检查分页参数
        dto.checkParam();
        //3.创建条件
        LambdaQueryWrapper<ApUserRealname> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(dto.getStatus()!=null,ApUserRealname::getStatus,dto.getStatus());
            //4.进行查询
        Page pageInfo = new Page(dto.getPage(),dto.getSize());
        //分页
        IPage page = page(pageInfo, queryWrapper);
        PageResponseResult result = new PageResponseResult(dto.getPage(), dto.getSize(), (int) page.getTotal());
        //取出分页数据，放在result对象中
        result.setData(page.getRecords());
        return result;
    }
}
